package hyit.app.dao.proxy;

import java.util.List;

import hyit.app.dao.IGroupInfoDAO;
import hyit.app.dao.impl.GroupInfoDAOImpl;
import hyit.app.dbc.DatabaseConnection;
import hyit.app.model.GroupInfo;

public class GroupInfoDAOProxy implements IGroupInfoDAO {
	private DatabaseConnection dbc = null;
	private IGroupInfoDAO dao = null;

	public GroupInfoDAOProxy() throws Exception {
		this.dbc = new DatabaseConnection();
		this.dao = new GroupInfoDAOImpl(this.dbc.getConnection());
	}

	@Override
	public boolean doCreate(GroupInfo groupInfo) throws Exception {
		boolean flag = false;
		try {
			if (this.dao.findByGidAndMemberId(groupInfo.getGid(),
					groupInfo.getMemberId()) == null) {
				this.dao.doCreate(groupInfo);
			}
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}

	@Override
	public boolean update(GroupInfo groupInfo) throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean delete(Integer number) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.delete(number);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}

	@Override
	public List<GroupInfo> findByGid(Integer number) throws Exception {
		List<GroupInfo> all = null;
		try {
			all = this.dao.findByGid(number);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return all;
	}

	@Override
	public List<GroupInfo> findByMemberId(Long number) throws Exception {
		List<GroupInfo> all = null;
		try {
			all = this.dao.findByMemberId(number);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return all;
	}

	@Override
	public GroupInfo findByGidAndMemberId(Integer gid, Long memberId)
			throws Exception {
		GroupInfo groupInfo = null;
		try {
			groupInfo = this.dao.findByGidAndMemberId(gid, memberId);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return groupInfo;
	}

}
